﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShevaEngine2GUI.Bindings
{
    /// <summary>
    /// Property binding.
    /// </summary>
    public class PropertyBinding : IBinding
    {
        /// <summary>Object instance.</summary>
        public object ObjectInstance;
        /// <summary>Property name.</summary>
        private string PropertyName;


        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="objectInstance"></param>
        /// <param name="propertyName"></param>
        public PropertyBinding(object objectInstance, string propertyName)
        {
            this.ObjectInstance = objectInstance;
            this.PropertyName = propertyName;
        }

        /// <summary>
        /// Get value.
        /// </summary>
        /// <returns></returns>
        public object GetValue()
        {
            if (this.ObjectInstance.GetType().GetProperty(this.PropertyName) != null)
                return this.ObjectInstance.GetType().GetProperty(this.PropertyName).GetValue(this.ObjectInstance, null);

            return null;
        }
    }
}
